package com.leet.code.simple_array;

/**
 * @description:
 * @author: WYG
 * @time: 2020/12/1 9:30
 */

public class ValidMountainArray {

    public boolean validMountainArray(int[] arr) {
        int length = arr.length;
        if (length < 3) {
            return false;
        }
        int flag = 0;
        for (int i = 1; i < length - 1; i++) {
            if (arr[i] == arr[i + 1] || arr[i] == arr[i - 1]) {
                return false;
            }
            if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
                flag = 1;
            }
            if (flag == 0 && arr[i] <= arr[i - 1]) {
                return false;
            }
            if (flag == 1 && arr[i] <= arr[i + 1]) {
                return false;
            }
        }
        return flag == 1;
    }

    public boolean other_validMountainArray(int[] arr) {
        int length = arr.length - 1;
        int i = 0;
        while (i < length && arr[i] < arr[i + 1]) {
            i++;
        }
        if (i == length || i == 0) {
            return false;
        }
        while(i < length && arr[i] > arr[i + 1]) {
            i++;
        }
        return i == length;
    }
}
